﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace ConsoleApp1
{

    public class Programs
    {
        private readonly string sqlCommaandString = "select * from Users";
        private readonly string connectionString = "server=.;database=Star;uid=sa;pwd=123456;";
        public static void PrinUser()
        {
            String connectionString = "server=.;database=Star;uid=sa;pwd=123456;";

            SqlConnection sqlConnection = new SqlConnection(connectionString);

            sqlConnection.Open();

            var sqlCommandString = "select * from Users";

            SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);

            Console.WriteLine("{0}\t{1}\t{2}", "name", "id", "age");

           

            var sdr = sqlCommand.ExecuteReader();

            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sdr["name"], sdr["id"], sdr["age"]);
            }
            sqlConnection.Close();

        }

        public void printUserInfoAdaper()
        {
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommaandString, connectionString);

            DataTable dataTable = new DataTable();

            dataAdapter.Fill(dataTable);

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine();

            Console.WriteLine("{0}\t{1}\t{2}","name","id", "age");

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["name"], dataTable.Rows[i]["id"], dataTable.Rows[i]["age"]);
            }


        }
    }
}
